/*
 * pml_bg.h
 *
 *  Created on: 2013幄1�7�1�7�1�7�1�7�1�7�1�7�1�7�1�7�1�7�1�7�1�7�1�7*      Author: lius
 */

#ifndef PML_BG_H_
#define PML_BG_H_

//#include "clist.h"

#if 0
typedef unsigned long  pml_sub_pat;
#define pml_sub_pat_conv(p) (*((pml_sub_pat*)p))
#else
typedef unsigned int  pml_sub_pat;
#define pml_sub_pat_conv(p) (((pml_sub_pat*)p)[0] | ((pml_sub_pat*)p)[1])
#endif
typedef struct _pat_stat_node_ {
	char grams[5];
	int pos_count[8];
	int count_all;
}pat_stat_node;

typedef struct _sub_pat_ {
	pml_sub_pat pat_array[50000];
//	struct {
//		pml_sub_pat hash;
//		unsigned int num;
//
//	}pat_array[50000];
	int pat_num;
}sub_pat_t;

typedef struct _pml_bg_ {
	char *shift_table;
	int groups;
	sub_pat_t sub_pat;

	int q_size;      //  [2,3]
	int q_gram_size; //  [2,3]
	int m_size;      //  [8,9]
	int act_bits;    //  = m_size - q_gram_size + 1
	int max_shift;   //  = m_size - q_gram_size
	int limit_score;

	pat_stat_node *pat_array;
	unsigned int array_size;
	pat_stat_node *all_pat_array;
	pat_stat_node *all_dst_array;
	int l_off,r_off;
	unsigned int pat_count;
	double avg_shift;
	int shift_count;
	unsigned int hit_count;
	unsigned int verify_count;
} pml_bg;

int pml_bg_init(pml_bg *pbg, int m_size, int q_size, int groups, int limit_score);
int pml_bg_add_pat(pml_bg *pbg, char*p, int len);
int pml_bg_match(pml_bg *pbg, char * buff, int len);
int pml_bg_pre_match(pml_bg *pbg);
int pml_bg_exit(pml_bg *pbg);


#endif /* PML_BG_H_ */
